<?php

/**
 * Project form base class.
 *
 * @package    ehockey
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormBaseTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
abstract class BaseFormDoctrine extends sfFormDoctrine
{
	protected $shouldDelete = false;

	public function setup()
	{
		if (isset($this['created_at'])) {
			unset($this['created_at']);
		};
		if (isset($this['updated_at'])) {
			unset($this['updated_at']);
		};
	}

	public function listenToFormPostConfigureEvent(sfEvent $event)
	{
		$form = $event->getSubject();

		if($form instanceof sfFormDoctrine && !$form->isNew())
		{
			$form->setWidget('delete_object', new sfWidgetFormInputCheckbox(array('label' => 'Eliminar')));
			$form->setValidator('delete_object', new sfValidatorPass());

			return $form;
		}

		return false;
	}

	protected function doSave($con = null) {
		if (!$this->shouldDelete) {
			parent::doSave($con);
		} else {
			if (null === $con)
			{
				$con = $this->getConnection();
			}
			if (!$this->isNew()) {
				$this->getObject()->delete($con);
			}
		}
	}
}